forcecell 2.2.0
Loading...
Searching...
No Matches
forcecell.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef FORCECELL_H
29#define FORCECELL_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_analog_in.h"
52#include "drv_i2c_master.h"
53
59
64
69
74#define FORCECELL_R6_KOHM 2.7
75#define FORCECELL_GAIN ( ( 100 / FORCECELL_R6_KOHM ) + 1 )
76#define FORCECELL_SENSITIVITY_V_V 0.025
77#define FORCECELL_FULL_SCALE_N 30
78
83#define FORCECELL_NUM_CONVERSIONS 100
84
89#define FORCECELL_TIMEOUT_MS 2000
90
95#define FORCECELL_ADC_RESOLUTION 0x0FFF
96#define FORCECELL_VREF_3V3 3.3
97#define FORCECELL_VREF_5V 5.0
98#define FORCECELL_VREF FORCECELL_VREF_3V3
99
105#define FORCECELL_SET_DEV_ADDR 0x4D
106 // forcecell_set
108
113
118
123#define FORCECELL_MAP_MIKROBUS( cfg, mikrobus ) \
124 cfg.an = MIKROBUS( mikrobus, MIKROBUS_AN ); \
125 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
126 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA );
127 // forcecell_map // forcecell
130
141
146typedef struct
147{
148 analog_in_t adc;
149 i2c_master_t i2c;
150
152 float vref;
155
157
162typedef struct
163{
164 pin_name_t an;
165 pin_name_t scl;
166 pin_name_t sda;
167
168 analog_in_resolution_t resolution;
169 float vref;
170
171 uint32_t i2c_speed;
172 uint8_t i2c_address;
173
175
177
188
194
205
221
236
248err_t forcecell_read_raw_adc ( forcecell_t *ctx, uint16_t *raw_adc );
249
261err_t forcecell_read_voltage ( forcecell_t *ctx, float *voltage );
262
275err_t forcecell_read_voltage_avg ( forcecell_t *ctx, uint16_t num_conv, float *voltage_avg );
276
288err_t forcecell_set_vref ( forcecell_t *ctx, float vref );
289
301
314err_t forcecell_read_force ( forcecell_t *ctx, float *force );
315
316#ifdef __cplusplus
317}
318#endif
319#endif // FORCECELL_H
320 // forcecell
322
323// ------------------------------------------------------------------------ END
forcecell_return_value_t
Force Cell Click return value data.
Definition forcecell.h:183
@ FORCECELL_OK
Definition forcecell.h:184
@ FORCECELL_ERROR
Definition forcecell.h:185
forcecell_drv_t
Force Cell Click driver selector.
Definition forcecell.h:136
@ FORCECELL_DRV_SEL_ADC
Definition forcecell.h:137
@ FORCECELL_DRV_SEL_I2C
Definition forcecell.h:138
err_t forcecell_read_raw_adc(forcecell_t *ctx, uint16_t *raw_adc)
Force Cell read raw ADC value function.
err_t forcecell_init(forcecell_t *ctx, forcecell_cfg_t *cfg)
Force Cell initialization function.
err_t forcecell_calib_offset(forcecell_t *ctx)
Force Cell calib offset function.
err_t forcecell_read_voltage_avg(forcecell_t *ctx, uint16_t num_conv, float *voltage_avg)
Force Cell read average voltage level function.
void forcecell_drv_interface_sel(forcecell_cfg_t *cfg, forcecell_drv_t drv_sel)
Force Cell driver interface setup function.
void forcecell_cfg_setup(forcecell_cfg_t *cfg)
Force Cell configuration object setup function.
err_t forcecell_read_force(forcecell_t *ctx, float *force)
Force Cell read force function.
err_t forcecell_set_vref(forcecell_t *ctx, float vref)
Force Cell set vref function.
err_t forcecell_read_voltage(forcecell_t *ctx, float *voltage)
Force Cell read voltage level function.
Force Cell Click configuration object.
Definition forcecell.h:163
analog_in_resolution_t resolution
Definition forcecell.h:168
float vref
Definition forcecell.h:169
uint32_t i2c_speed
Definition forcecell.h:171
pin_name_t scl
Definition forcecell.h:165
pin_name_t sda
Definition forcecell.h:166
forcecell_drv_t drv_sel
Definition forcecell.h:174
pin_name_t an
Definition forcecell.h:164
uint8_t i2c_address
Definition forcecell.h:172
Force Cell Click context object.
Definition forcecell.h:147
float vref
Definition forcecell.h:152
i2c_master_t i2c
Definition forcecell.h:149
float zero_force_offset
Definition forcecell.h:154
uint8_t slave_address
Definition forcecell.h:151
forcecell_drv_t drv_sel
Definition forcecell.h:153
analog_in_t adc
Definition forcecell.h:148